package cn.wolfcode.luowowo.website.advice;

import cn.wolfcode.luowowo.common.exception.LogistException;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@ControllerAdvice
public class CommonAdvice {



        @ExceptionHandler(LogistException.class)
        @ResponseBody
        public Object LoginException(Exception e) throws IOException {
            return new AjaxResult(false,e.getMessage());
        }

        @ExceptionHandler(RuntimeException.class)
        public void Exception2(Exception e, HttpServletResponse response) throws IOException {
            e.printStackTrace();
            response.setContentType("text/json;charset=utf-8");
            response.getWriter().write(JSON.toJSONString(new AjaxResult(false,"未知异常")));
        }

}
